package com.zw.cloud.common.thread.pool;

import cn.hutool.core.thread.NamedThreadFactory;

import java.util.Objects;
import java.util.concurrent.*;

public class ThreadExecutorPool {

    public static ExecutorService msgThreadPoolExecutor = getExecutorService();

    private static ExecutorService getExecutorService() {
        if (Objects.isNull(msgThreadPoolExecutor)) {
            synchronized (ThreadExecutorPool.class) {
                if (Objects.isNull(msgThreadPoolExecutor)) {
                    msgThreadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors() * 2, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(1024), new NamedThreadFactory("thread-pool-msg",true),new ThreadPoolExecutor.CallerRunsPolicy());
                }
            }
        }
        return msgThreadPoolExecutor;
    }
}
